home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.unix.programmer
- Path: phcoms4.seri.philips.nl!panther!baynes
- From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
- Subject: fgetc and getc (was Q: '\n' character)
- Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
- Message-ID: <Dq1s7F.Bo1@ukpsshp1.serigate.philips.nl>
- Date: Thu, 18 Apr 1996 07:45:15 GMT
- References: <4kj66f$k0o@ren.cei.net> <4ku8f9$d3o@mark.ucdavis.edu> <4kumbqINNgcr@mayne.ugrad.cs.ubc.ca> <4l13uu$mva@mark.ucdavis.edu> <4l1ap4INNhsc@keats.ugrad.cs.ubc.ca>
- Organization: Philips Semiconductors, Southampton, UK
- X-Newsreader: TIN [version 1.2 PL2]
- Followup-To: comp.lang.c,comp.unix.programmer
-
- Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) wrote:
- : Also, you used fputc() and fgetc(). These are not likely to be as fast as the
- : getc() and putc() macro equivalents which access the FILE structure's buffer
- : directly. (Do you know the implementation details of these functions/macros on
- : the system that served as your testbench?)
-
- As far as ANSI C is concerned they are all functions, and any library function
- can also have a macro implementation hiding it. It is a convention of
- unix implementations that getc is a macro and fgetc is a function. As far
- as I am aware the unix standards (POSIX and XOPEN) just require the C compiler
- to be ANSI so there is no guarentee that you will a macro for getc.
- Note however ANSI C does relax the rules slightly for getc and putc, if they
- are implemented as a macro they can evaluate their argument more than once,
- which fgetc and fputc cannot. This might make macro implementations of getc
- and putc more efficient than ones of fgetc and fputc.
- You also make the assumption that macros must be faster than functions.
- It is often true that they are, but they don't have to be. For example a
- function hand written in assembler may be faster than anything the C compiler
- can do with a macro. In fact an implementor would not bother with providing
- a macro for getc if a function would do it faster.
-
- The end result of your reasoning is correct, getc and putc will normally be no
- slower than fgetc and fputc and probably faster, but the reason is because
- the implementor can exploit weaker rules on argument evaluation. However there
- are plenty of pathologies, for example if the arguments are complex then the
- extra evaluation could cost more.
-
- --
- Stephen Baynes baynes@ukpsshp1.serigate.philips.nl
- Philips Semiconductors Ltd
- Southampton My views are my own.
- United Kingdom
- Are you using ISO8859-1? Do you see ⌐ as copyright, ≈ as division and ╜ as 1/2?
-